package com.sq.partner.manager.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.dao.ICoreDeptDao;
import com.sq.partner.manager.dao.IGatewayChannelInfoConfigDao;
import com.sq.partner.manager.dao.IGatewayCustomerDao;
import com.sq.partner.manager.dao.IGatewayPolicyDao;
import com.sq.partner.manager.dao.IGatewayPolicyProtocolDao;
import com.sq.partner.manager.dao.IGatewaySubChannelDao;
import com.sq.partner.manager.mybatis.model.CoreDept;
import com.sq.partner.manager.mybatis.model.GatewayChannelInfo;
import com.sq.partner.manager.mybatis.model.GatewayPolicy;
import com.sq.partner.manager.mybatis.model.GatewayUser;
import com.sq.partner.manager.mybatis.model.TreeDto;
import com.sq.partner.manager.service.IGatewayProtocolPolicyListService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.excel.ExcelEntity;
import com.sq.partner.manager.util.excel.ExportExcelBuilderTool;
@Service
public class GatewayProtocolPolicyListServiceImpl implements IGatewayProtocolPolicyListService {
	
	@Resource
	ExportExcelBuilderTool exportExcelBuilderTool;
	
	@Resource
	private ICoreDeptDao coreDeptDao;
	
	@Resource
	private IGatewayChannelInfoConfigDao channelInfoConfigDao;
	
	@Resource
	private IGatewayPolicyProtocolDao gatewayPolicyProtocolDao;

	
	//查询用户权限
	@Override
	public List<CoreDept> queryPrivilegeBranch(String deptCodeStr)
			throws Exception {

		return coreDeptDao.queryDeptList(deptCodeStr);
	}
	//出单机构
	@Override
	public Page<CoreDept> queryDeptPageByDeptAndParentDeptCode(Page<CoreDept> page,
			String parentDeptCode) throws Exception {
		return coreDeptDao.queryCoreDeptPageByParentCode(page, parentDeptCode);
	}
	//查询合作伙伴
	@Override
	public Page<GatewayChannelInfo> queryChannelInfoPageOfLife(
			Page<GatewayChannelInfo> page) throws Exception {
		return channelInfoConfigDao.queryChannelInfoPageOfLife(page);
	}
	//验证合作伙伴
	@Override
	public List<Map> queryChannelListOfProtocol(GatewayChannelInfo channelInfo,
			String flag) throws Exception {
		return channelInfoConfigDao.queryChannelInfoList(channelInfo,flag);
	}
	//条件分页查询车捷保保单
	@Override
	public Page<Map<String,Object>> queryProtocolPolicyPageByCriteria(Page page) throws Exception {
		// TODO Auto-generated method stub
		return gatewayPolicyProtocolDao.queryProtocolPolicyPageByCriteria(page);
	}
	//下载电子保单查询
	@Override
	public List<Map<String, Object>> queryProtocolPolicyListByCriteria(
			Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		return gatewayPolicyProtocolDao.queryProtocolPolicyListByCriteria(map);
	}
	//电子保单下载
	@Override
	public void downloadProtocolPolicyFile(
			List<Map<String, Object>> protocolPolicyList,
			HttpServletResponse response) throws Exception {
		
		ExcelEntity excel = new ExcelEntity();
		excel.setResults(protocolPolicyList);
		excel.setFileName("ProtocolPolicyInfo");
		excel.setTitles("保单号,延保协议编号,方案,被保人名称,合作伙伴,保费,起保日期,终保日期,收款日期,保单状态,批单号");
		excel.setTitleKeys("POLNO,PROTOCOL_NO,PLAN_NAME,COND1,CHANNEL_NAME,PREMIUM,BEGIN_DATE,END_DATE,RCV_PREM_DATE,RCV_PREM_STATUS,ENDORSENO");
		excel.setColumns("27,30,35,15,35,15,12,12,12,10,35");

		exportExcelBuilderTool.buildExcel(response,excel);
		
	}
	//根据保单号查询保单信息
	@Override
	public Map<String, Object> queryProtocolById(String polno) throws Exception {
		// TODO Auto-generated method stub
		return gatewayPolicyProtocolDao.queryProtocolById(polno);
	}
	//编辑保单
	@Override
	public void saveUpProtocol(Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		gatewayPolicyProtocolDao.saveUpProtocol(map);
	}
	//批量更新实收状态
	@Override
	public Map<String, Integer> batchUpdate(List<Map<String, Object>> lists) throws Exception {
		// TODO Auto-generated method stub
		return gatewayPolicyProtocolDao.batchUpdate(lists);
	}
	//查询保单号验证
	@Override
	public List<String> queryPolno(String polnos) throws Exception {
		// TODO Auto-generated method stub
		return gatewayPolicyProtocolDao.queryPolno(polnos);
	}
	
	
	
	
	
	
	
	
	
}
